package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.mvpframe.client.widget.mescroll.UpAndDownCallBack;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.utils.SpecialConfigUtils;
import com.superman.supermarket.client.view.home.HomeView;

/**
 * 首页
 * 
 * @author superman
 * @version 2018年8月2日下午5:17:37
 */
public class HomeActivity extends ShopAbstractActivity implements UpAndDownCallBack {

	private HomeView homeView;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月21日 下午4:18:16
	 * @param homeView
	 */
	@Inject
	public HomeActivity(HomeView homeView) {
		this.homeView = homeView;
	}

	@Override
	public void getListDataByPage(int page) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("SPECIAL_ID", SpecialConfigUtils.getHomeRecommandSpecialId());
		map.put("PAGE_INDEX", page);

		postman.post("/special/querySkus", map, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				List<Map<String, Object>> list = XJsonUtil.getList(response);
				homeView.getPullToRefreshView().endBySize(list, XJsonUtil.getCount(response));
			}
		});

	}

	@Override
	public IPageView getView() {
		return homeView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onActivity(EventBus eventBus) {
		// TODO Auto-generated method stub
	}

	@Override
	public void popToRefresh() {
	}

	@Override
	public void popToRefresh(Object contextData) {
	}

	@Override
	public void pushToRefresh() {
		homeView.getPullToRefreshView().initMeScroll(this);
	}

}
